package com.gewu.pm.ui.adapter.approval;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.gewu.pm.R;
import com.gewu.pm.app.AppAdapter;
import com.gewu.pm.bean.ApprovalApplicationBean;

/**
 * 抄送我的列表适配器
 */
public class CcToMeAdapter extends AppAdapter<ApprovalApplicationBean> {

    public CcToMeAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ItemViewHolder();
    }

    private final class ItemViewHolder extends AppAdapter<?>.ViewHolder {

        private final TextView mTitleView;
        private final TextView mStatusView;
        private final TextView mApplyTimeView;
        private final TextView mApplicantView;
        private final TextView mReasonView;
        private final TextView mSupplementTimeView;

        private ItemViewHolder() {
            super(R.layout.cc_to_me_item);
            mTitleView = findViewById(R.id.tv_title);
            mStatusView = findViewById(R.id.tv_status);
            mApplyTimeView = findViewById(R.id.tv_apply_time);
            mApplicantView = findViewById(R.id.tv_applicant);
            mReasonView = findViewById(R.id.tv_reason);
            mSupplementTimeView = findViewById(R.id.tv_supplement_time);
        }

        @Override
        public void onBindView(int position) {
            ApprovalApplicationBean item = getItem(position);
            
            mTitleView.setText(item.getTitle());
            mApplyTimeView.setText("2025-8-18 19:30");
            mApplicantView.setText("张三");
            mReasonView.setText("该区域为补卡事由");
            mSupplementTimeView.setText("2025-8-18 19:30");
            
            // 设置状态标签
            mStatusView.setText(item.getStatusText());
            
            // 根据状态类型设置不同的背景和文字颜色
            switch (item.getType()) {
                case 1: // 待审批
                    mStatusView.setBackgroundResource(R.drawable.shape_label_red);
                    mStatusView.setTextColor(getColor(R.color.red_app));
                    break;
                case 2: // 已通过
                    mStatusView.setBackgroundResource(R.drawable.shape_label_green);
                    mStatusView.setTextColor(getColor(R.color.green_label));
                    break;
                case 3: // 已驳回
                    mStatusView.setBackgroundResource(R.drawable.shape_label_orange);
                    mStatusView.setTextColor(getColor(R.color.orange_01));
                    break;
            }
        }
    }
}
